//
//  LaunchGifViewthree.m
//  safeLady
//
//  Created by xmy on 2016/12/15.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "LaunchGifViewthree.h"
@interface LaunchGifViewthree ()
@property (weak, nonatomic) IBOutlet UIImageView *huabanImg;
@property (weak, nonatomic) IBOutlet UIImageView *qunzhongImg;
@property (weak, nonatomic) IBOutlet UIImageView *fatherImg;
@property (weak, nonatomic) IBOutlet UIImageView *motherImg;
@property (weak, nonatomic) IBOutlet UIImageView *superManImg;
@property (weak, nonatomic) IBOutlet UIImageView *comeNowImg;
@property (weak, nonatomic) IBOutlet UIImageView *fatherCome;
@property (weak, nonatomic) IBOutlet UIImageView *callPolice;
@property (weak, nonatomic) IBOutlet UIImageView *motherCome;
@property (weak, nonatomic) IBOutlet UIImageView *supermanCome;
@property (weak, nonatomic) IBOutlet UIView *layerView;
@property (assign, nonatomic) BOOL animationOnce;
@property (weak, nonatomic) IBOutlet UIImageView *backGroundImg;
@end
@implementation LaunchGifViewthree

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)awakeFromNib{
    [super awakeFromNib];
    self.huabanImg.hidden =YES;
    self.qunzhongImg.hidden = YES;
    [self.backGroundImg setTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [SharedAppDelegate openAppMainVCT];
        
    }];
}
-(void)animationStart{
    @weakify(self)
    if(self.animationOnce){
        return;
    }
    self.huabanImg.hidden =NO;
    self.qunzhongImg.hidden = NO;
    self.animationOnce = YES;
    CABasicAnimation *momAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    momAnimation.toValue = [NSNumber numberWithFloat:109];
    momAnimation.duration = 0.4f;
    momAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    momAnimation.fillMode =kCAFillModeForwards;
    momAnimation.removedOnCompletion = NO;
    [self.qunzhongImg.layer addAnimation:momAnimation forKey:@"transformAnimation"];
    [UIView animateWithDuration:0.2 animations:^(void){
        @strongify(self)
        self.fatherCome.alpha=1.0f;
    }];
    
    CABasicAnimation *momAnimation1 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    momAnimation1.toValue = [NSNumber numberWithFloat:109];
    momAnimation1.duration = 0.4f;
    momAnimation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    momAnimation1.fillMode =kCAFillModeForwards;
    momAnimation1.removedOnCompletion = NO;
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3/*延迟执行时间*/ * NSEC_PER_SEC));
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        @strongify(self)
        [UIView animateWithDuration:0.2 animations:^(void){
            @strongify(self)
            self.callPolice.alpha=1.0f;
        }];
        [self.huabanImg.layer addAnimation:momAnimation1 forKey:@"transformAnimation1"];
    });
    
    CABasicAnimation *momAnimation2 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    momAnimation2.toValue = [NSNumber numberWithFloat:-101];
    momAnimation2.duration = 0.4f;
    momAnimation2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    momAnimation2.fillMode =kCAFillModeForwards;
    momAnimation2.removedOnCompletion = NO;
    [self.fatherImg.layer addAnimation:momAnimation2 forKey:@"transformAnimation2"];
    [UIView animateWithDuration:0.2 animations:^(void){
        @strongify(self)
        self.comeNowImg.alpha=1.0f;
    }];
    
    CABasicAnimation *momAnimation3 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    momAnimation3.toValue = [NSNumber numberWithFloat:-115];
    momAnimation3.duration = 0.4f;
    momAnimation3.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    momAnimation3.fillMode =kCAFillModeForwards;
    momAnimation3.removedOnCompletion = NO;
    dispatch_time_t delayTime1 = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6/*延迟执行时间*/ * NSEC_PER_SEC));
    dispatch_after(delayTime1, dispatch_get_main_queue(), ^{
        @strongify(self)
        [UIView animateWithDuration:0.2 animations:^(void){
            @strongify(self)
            self.motherCome.alpha=1.0f;
        }];
        [self.motherImg.layer addAnimation:momAnimation3 forKey:@"transformAnimation3"];
    });
    
    CABasicAnimation *momAnimation4 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    momAnimation4.toValue = [NSNumber numberWithFloat:60];
    momAnimation4.duration = 0.3f;
    CABasicAnimation *momAnimation5 = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
    momAnimation5.toValue = [NSNumber numberWithFloat:60];
    momAnimation5.duration = 0.3f;
    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
    groupAnimation.animations = [NSArray arrayWithObjects:momAnimation4,momAnimation5, nil];
    groupAnimation.duration = 0.3f;
    groupAnimation.fillMode =kCAFillModeForwards;
    groupAnimation.removedOnCompletion = NO;
    groupAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    dispatch_time_t delayTime2 = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.9/*延迟执行时间*/ * NSEC_PER_SEC));
    dispatch_after(delayTime2, dispatch_get_main_queue(), ^{
        @strongify(self)
        [UIView animateWithDuration:0.2 animations:^(void){
            @strongify(self)
            self.supermanCome.alpha=1.0f;
            self.superManImg.alpha=1.0f;
        }];
        [self.superManImg.layer addAnimation:groupAnimation forKey:@"groupAnimation"];
    });
    [UIView animateWithDuration:0.8 delay:1.2 options:UIViewAnimationOptionCurveLinear animations:^(void){
        self.layerView.alpha =0.f;
    } completion:^(BOOL finish){
        
    }];

}

@end
